package com.college.collegeinfomanage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.college.collegeinfomanage.dto.UniversityDTO;
import com.college.collegeinfomanage.entity.University;
import com.college.collegeinfomanage.mapper.UniversityMapper;
import com.college.collegeinfomanage.service.UniversityService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UniversityServiceImpl extends ServiceImpl<UniversityMapper, University> implements UniversityService {

    @Resource
    private UniversityMapper universityMapper;

    @Override
    public IPage<University> getPage(UniversityDTO universityDTO) {
        LambdaQueryWrapper<University> queryWrapper = new LambdaQueryWrapper<>();
        String name = universityDTO.getName();
        if (name != null && !name.trim().isEmpty()) {
            queryWrapper.like(University::getName, name);
        }
        String schoolNature = universityDTO.getSchoolNature();
        if (schoolNature != null && !schoolNature.trim().isEmpty()) {
            queryWrapper.eq(University::getSchoolNature, schoolNature);
        }
        // 创建分页对象，current 表示当前页码，size 表示每页记录数
        Page<University> page = new Page<>(universityDTO.getPage(), universityDTO.getSize());
        // 执行分页查询
        IPage<University> userPage = universityMapper.selectPage(page,queryWrapper);
        return userPage;
    }
}
